package Application.Mirrors;

import Application.AppJoint;
import Application.Layer.Layer;
import Application.Layer.LayerDelegate;

public class BlackColorMirror extends Mirror{
    public static BlackColorMirror getInstance() {
        return ins;
    }

    private static BlackColorMirror ins = new BlackColorMirror();

    public void blackColorMirrorActivited(Layer layer){
        int height = AppJoint.getInstance().getCanvasHeight();
        int width = AppJoint.getInstance().getCanvasWidth();

        int argb;

        int ans;
        for(int i=0;i<width;i++){
            for(int j=0;j<height;j++){
                argb = layer.getArgb(i,j);
                int a = (argb >> 24) & 0xff;
                int r = (argb & 0x00ff0000) >> 16;
                int g = (argb & 0x0000ff00) >> 8;
                int b = (argb & 0x000000ff);

                int a2 = a;
                int r2 = (r+g+b)/3;
                int g2 = (r+g+b)/3;
                int b2 = (r+g+b)/3;

                ans = (a2<<24)|(r2<<16)|(g2<<8)|(b2);

                layer.setArgb(i,j,ans);
            }
        }
        LayerDelegate.getInstance().refreshAll();
        AppJoint.getInstance().flush();
    }
}
